package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.user.OrdersService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author wangqi
 * @date 2024/1/5 10:44
 */
@Slf4j
@RestController
@RequestMapping("/admin")
public class OrderController {
    @Autowired
    private OrdersService ordersService;

    //订单分页+条件搜索
    @GetMapping("/order/conditionSearch")
    public Result<PageResult> conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO){
        log.info("管理端订单条件+分页查询：{}",ordersPageQueryDTO);
        PageResult pageResult = ordersService.pageQuery(ordersPageQueryDTO);
        return Result.success(pageResult);
    }

    @GetMapping("/order/statistics")
    public Result<OrderStatisticsVO> statistics(){
        log.info("统计各种订单状态的数量：");
        OrderStatisticsVO orderStatisticsVO = ordersService.statistics();
        return Result.success(orderStatisticsVO);
    }

    @GetMapping("/order/details/{id}")
    public Result<OrderVO> orderDetail(@PathVariable Long id){
        log.info("根据订单id查询订单详情：id={}",id);
        OrderVO orderVO = ordersService.findOrdersById(id);
        log.info("查询到订单详情：{}",orderVO);
        return Result.success(orderVO);
    }

    @PutMapping("/order/cancel")
    public Result cancel(@RequestBody OrdersCancelDTO ordersCancelDTO){
        log.info("取消订单，订单id={}",ordersCancelDTO.getId());
        ordersService.cancel(ordersCancelDTO);
        return Result.success();
    }


    @PutMapping("/order/confirm")
    public Result confirm(@RequestBody OrdersConfirmDTO ordersConfirmDTO){
        log.info("管理端接单：{}",ordersConfirmDTO);
        ordersService.confirm(ordersConfirmDTO);
        return Result.success();
    }

    //order/delivery/{id}
    @PutMapping("order/delivery/{id}")
    public Result delivery(@PathVariable Long id){
        log.info("管理端派送：订单id={}",id);
        ordersService.delivery(id);
        return Result.success();
    }

    @PutMapping("order/complete/{id}")
    public Result complete(@PathVariable Long id){
        log.info("管理端完成订单：订单id={}",id);
        ordersService.complete(id);
        return Result.success();
    }

    @PutMapping("/order/rejection")
    public Result reject(@RequestBody OrdersRejectionDTO ordersRejectionDTO){
        log.info("管理端拒绝接单：{}",ordersRejectionDTO);
        ordersService.reject(ordersRejectionDTO);
        return Result.success();
    }
}
